<template>
	<view class="">
		<view class="">
			<view class="">
				<image :src="image" style="width: 100%;  height: 300rpx;" mode="scaleToFill"></image>
			</view>
			<view class="searchBox">
				<view class="searchContext">
				<u-cell-group>
					<u-cell-item  center :value="assessInfo.carName"
						:value-style="{'color':'#666'}" @click="clickCar" :arrow="true" title="选择车型">
					</u-cell-item>

				</u-cell-group>
				</view>
				<!-- <view class="_flex _justify_between" style="margin-top: 50rpx;">
					<view class="" style="width: 30%;">
						<u-button type="primary" plain @click="goSearch">样例</u-button>
					</view>
					<view class="" style="width: 60%;">
						<u-button type="primary" @click="goSearchTwo">开始查询</u-button>
					</view>
				</view> -->
				<view class="buttons">
					
					<view class="kscx" @click="goSearchTwo">
						开始查询
					</view>
					<view class="ckyl"  @click="goSearch">
						查看样例
					</view>
				</view>
				<view class="xy" style="margin-top: 40rpx;">
					<u-checkbox-group>
						<u-checkbox active-color="#002B56" v-model="form.checked" shape="circle" @change="uerAgreement">
							<text class="tip">使用本服务意味着您已经阅读并同意</text>
							<text class="tip" style="color: #002B56;" @click="goUserAgreement">《用户协议》</text>
						</u-checkbox>
					</u-checkbox-group>
					
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import API from "@/api/report.js"
	export default {
		data() {
			return {
				form: {
					checked: true
				},
				vinNo: '',
				image: 'https://pxhuodong.oss-cn-beijing.aliyuncs.com/ibuycar/swiper/swiper01.png?' + new Date().getTime(),
				assessInfo:{
					ppai:"",
					cxing:"",
					cx:"",
					carName:"请选择",
				},
			};
		},
		onShow() {
			const json = getApp().globalData.carCondition
			console.log("选中的数据")
			console.log(json)
			if (getApp().globalData.carCondition) {
				this.assessInfo.ppai = json.ppai
				this.assessInfo.cxing = json.cxing
				this.assessInfo.cx = json.cx
				this.assessInfo.year = json.cxing.substring(0,4)
				this.assessInfo.carName = json.cxing || json.cx ||  json.ppai
			} else {
				this.assessInfo.carName = '请选择'
			}
		},
		methods: {
			uerAgreement(e){
				console.log(e);
				this.form.checked = e.value;
			},
			goUserAgreement(){
				uni.navigateTo({
					url: "/pages/login/userAgreement"
				})
			},
			// 选择车型
			clickCar() {
				uni.navigateTo({
					url: "/pagesA/selectCar/selectCarComplaint"
				})
			},
			goSearch() {
				uni.navigateTo({
					url: "./complainSelectResult"
				})
			},
			goSearchTwo() {
				console.log(this.form.check);
				if(!this.assessInfo.cxing || !this.assessInfo.cx){
					this.$u.toast('请先选择车型');
					return false
				}
				if(this.form.checked == false){
					this.$u.toast('请阅读并同意用户协议！');
					return false
				}
				let data = {
					cxing:this.assessInfo.cxing,
					cx:this.assessInfo.cx,
					pp:this.assessInfo.ppai,
				}
				API.getVin(data).then(res=>{
					console.log(res);
					if(res.code == 200){
						getApp().globalData.carCondition =""
						uni.navigateTo({
							url: `./comTwo?item=${encodeURIComponent(JSON.stringify(res.data))}&year=${this.assessInfo.year}`
						})
						
					}

				})
			},
			// goSearchTwo() {
			// 	if (this.vinNo) {
			// 		API.getVin({
			// 			vin: this.vinNo
			// 		}).then(res => {
			// 			if (res.data) {
			// 				uni.navigateTo({
			// 					url: `./comTwo?item=${encodeURIComponent(JSON.stringify(res.data))}`
			// 				})
			// 			} else {
			// 				this.$u.toast(res.message || '请求失败');
			// 				return false
			// 			}
			// 		})
			// 	} else {
			// 		this.$u.toast('请先填写VIN号');
			// 	}
			// },
			scanCode() {
				var that = this;
				uni.scanCode({
					success: function(res) {
						console.log(res)
					}
				});
			},
		}
	};
</script>
<style scoped lang="scss">
	.buttons{
		view{
			margin-top: 40rpx;
		}
	}
	.kscx{
		width: 100%;
		background: #002B56;
		border-radius: 8rpx;
		height: 88rpx;
		line-height: 88rpx;
		color: #fff;
		font-family: PingFangSC-Regular;
		font-size: 36rpx;
		color: #FFFFFF;
		text-align: center;
	}
	.ckyl{
		font-family: PingFangSC-Regular;
		font-size: 36rpx;
		color: #002B56;
		text-align: center;
	}
	.searchBox {
		padding: 24rpx;
	}

	.searchBox .searchContext {
		background: #fff;
		display: flex;
		/* width: 500rpx; */
		padding: 0 0;
		border-radius: 10rpx;
		font-size: 40rpx;
		color: #002B56;
		border: 1px solid #eee;
	}

	.tip {
		font-size: 24rpx;
	}
	u-cell-group{
		width: 100%;
		background-color: #fff;
		
	}
	u-checkbox-group{ margin-right: 0;}
	.xy{ display: flex; align-items: center;}
</style>
<style>
	page {
		background-color: #fff;
	}
</style>
